package com.tzy;

import sun.plugin2.message.Message;

import java.text.MessageFormat;
import java.util.Scanner;

public class VersionAlliance9 {
    static Scanner input=new Scanner(System.in);
    static String[] names=new String[8];  //存储订单人姓名
    static String[] dishMegs={"红烧鲫鱼","宫保鸡丁","鱼香肉丝","臭鳜鱼","糖醋排骨"};//用来存储菜品信息的数组
    static int[] numbers=new int[10]; //存储菜品分数
    static double[] price={38.0,24.0,49.0,74.0,55.0};   //用来存储菜品单价信息的数组
    static String[] addresses=new String[8];//存储送餐地址
    static int[] praiseNums=new int[10];
    static int[] times=new int[10];//用来存储时间点
    static boolean[] states=new boolean[10];//表示订单状态的数组  true表示已完成，false表示已预定
    static double[] sumPrices=new double[8];//保存订单总金额

    public static void initData() {
        //初始化第一条订单
        names[0]="张晴";
        dishMegs[0]="红烧鲫鱼";
        numbers[0]=2;
        times[0]=12;
        sumPrices[0]=76.0d;
        addresses[0]="包河区屯溪路193号";
        states[0]=false;

        //初始化第二条订单
        names[1]="张晴";
        dishMegs[1]="宫保鸡丁";
        numbers[1]=2;
        times[1]=14;
        sumPrices[1]=24.0d;
        addresses[1]="包河区屯溪路193号";
        states[1]=true;

        //初始化第三条订单
        names[2]="张晴";
        dishMegs[2]="鱼香肉丝";
        numbers[2]=2;
        times[2]=15;
        sumPrices[2]=49.0d;
        addresses[2]="包河区屯溪路193号";
        states[2]=false;
    }
    //在主方法放置主菜单相关代码
    public static void main(String[] args) {
        initData();
        int num=0;
        boolean isExit=false;
        int choice;
        do {
            System.out.println("\t欢迎使用“吃货联盟订餐系统”");
            System.out.println("*********************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("*********************************");
            System.out.print("请选择，输入菜单序号:");
            if (input.hasNextInt()){
                choice=input.nextInt();
            }else{
                System.out.print("你输入的菜单序号无效！");
                input=new Scanner(System.in);    //防止输入失效
                continue;
            }
            switch(choice){
                case 1: {

                    orderFood();
                    break;
                }
                case 2: {
                    viewMealBags();
                    break;
                }
                case 3:{
                    signOrder();
                    break;
                }
                case 4:{
                    deleteOrder();
                    break;
                }
                case 5:{
                    dianZan();
                    break;
                }
                case 6:{
                    System.out.println("6.退出系统");
                    System.out.println("谢谢使用，欢迎下次光临！");
                    System.exit(0);   //正常退出程序
                    break;
                }
                default:
                    System.out.println("\n你输入的订单号错误！");
                    break;
            }
            if(!isExit){
                System.out.println();
                System.out.print("请输入0返回主菜单，请输入：");
                num=input.nextInt();
            }else{
                break;    //退出系统
            }
        } while (num==0);
    }
    //1.我要订餐
    public static void orderFood() {
        System.out.println("当前的位置：吃货联盟订单系统>>我要订餐");
        System.out.print("请输入订餐人姓名：");
        String names=input.next();
        for (int i = 0; i < dishMegs.length; i++) {
            System.out.println((i+1)+"."+dishMegs[i]);
        }
        System.out.print("请输入需要的菜品序号：");
        int number = input.nextInt();
        System.out.println("你选择的是：\t"+number+".\t" + dishMegs[number-1] + "\t单价：" + price[number-1]);
        System.out.print("请选择份数：");
        int number1 = input.nextInt();
        if (number1 <= 20) {
            System.out.print("你点了" + number1 + "份");
            System.out.println();
        } else {
            System.out.println("抱歉阿，咱家没有那么多狮子");
        }
        System.out.print("请输入送餐时间（营业时间：10~20时，请输入整数）：");
        for (int j = 1; j < 10; j++) {
            int number2 = input.nextInt();
            if (number2 >= 10 && number <= 20) {
                break;
            } else {
                System.out.print("输入错误，请重新输入:");
            }
        }
        System.out.print("请输入送餐地址：");
        for (int j = 0; j < 10; j++) {
            String site = input.next();
            if (site != null) {
                System.out.println("输入成功，么么哒！");
                break;
            } else {
                System.out.println("请重新输入：");
            }
        }
        System.out.println("当前状态：已预定;");
        System.out.println();
        double sumPrice = number1 * price[number-1];
        System.out.println("您的当前金额为：" + sumPrice);
        System.out.println("正在计算是否需要运费！");
        if (sumPrice>=50){
            System.out.println("不需要运费！"+"\n"+"您的总金额为：" +sumPrice);
        }else{
            System.out.println("需要运费6元！"+"\n"+"您的总金额为：" + (sumPrice+6));
        }
    }

    //2.查看餐袋
    public static void viewMealBags() {
        //以列表的形式展示订单信息列表
        //1.显示当前位置（面包屑导航）
        System.out.println("当前的位置：吃货联盟订单系统>>查看餐袋");
        //2.表头
        System.out.println("序号"+"\t"+"订餐人"+"\t"+"菜品信息"+"\t"+"送餐时间"+"\t"+"送餐地址"+"\t\t"+"总金额"+"\t"+"订单状态");
        //显示订单数据
        for (int i = 0; i < names.length; i++) {
            if (names[i]!=null){
                String state = (states[i]==false)?"已预定":"已完成";
                String data=times[i]+"点";
                String sumPrice=sumPrices[i]+"元";
                System.out.println((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+data+"\t"+addresses[i]+"\t"+sumPrice+"\t"+state);
            }
        }
    }
    //3.签收订单
    public static void signOrder() {
        System.out.println("当前的位置：吃货联盟订单系统>>签收订单");
        boolean isSignFind=false;
        System.out.print("请选择要签收的订单号：");
        int signOrderld=input.nextInt();
        for (int i = 0; i < names.length; i++) {
            if(names[i]!=null&&states[i]==false&&signOrderld==i+1) {
                states[i] = true;//将状态值设置为已完成
                System.out.println("订单签收成功！");
                isSignFind = true;//标记找到此订单
            }else
                if(names[i]!=null&&states[i]==true&&signOrderld==i+1){
                    System.out.println("您选择的订单已完成签收，不能再次签收！");
                    isSignFind = true;//标记找到此订单
            }
        }
        if(!isSignFind){
            System.out.println("您选择的订单不存在！");
        }
    }
    //4.删除订单
    public static void deleteOrder() {
        System.out.println("当前的位置：吃货联盟订单系统>>删除订单");
        boolean isDelFind = false;
        System.out.print("请输入要删除的订单号：");
        int delld = input.nextInt();
        for (int i = 0; i < names.length; i++) {
            if (names[i] != null && states[i] == true && delld == i + 1) {
                isDelFind = true;
                for (int j = delld - 1; j < names.length - 1; j++) {
                    names[j] = names[j + 1];
                    dishMegs[j] = dishMegs[j + 1];
                    times[j] = times[j + 1];
                    addresses[j] = addresses[j + 1];
                    sumPrices[j] = sumPrices[j + 1];
                    states[j] = states[j + 1];
                }
                int endIndex = names.length - 1;
                names[endIndex] = null;
                dishMegs[endIndex] = null;
                times[endIndex] = 0;
                addresses[endIndex] = null;
                states[endIndex] = false;
                sumPrices[endIndex] = 0;
                System.out.println("删除订单成功");
                break;
            } else if (names[i] != null && states[i] == false && delld == i + 1) {
                System.out.println("您选择的订单未签收，不能删除");
                isDelFind = true;
                break;
            }
        }
        if (!isDelFind) {
            System.out.println("您要删除的订单不存在");
        }
    }
    //5.我要点赞
    public static void dianZan() {
        System.out.println("当前的位置：吃货联盟订单系统>>我要点赞");
        for (int i = 0; i < dishMegs.length; i++) {
            String prices = price[i] + "元";
            String priaiseNum = (praiseNums[i] > 0 ? praiseNums[i] + "赞":"");
            System.out.println((i + 1) + "\t" + dishMegs[i] + "\t" + prices + "\t" + priaiseNum);
        }
        System.out.print("请选择您要点赞的菜品：");
        int priaiseNum = input.nextInt();
        praiseNums[priaiseNum - 1]++;
        System.out.println("点赞成功");
    }
}
